package com.ymatou.iapi.tradingsettlement.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymatou.iapi.tradingsettlement.bean.HunterCatalogSettlementDetailBean;
import com.ymatou.iapi.tradingsettlement.bean.HunterFeeTypeRelationBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.HunterCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceHunterOrderCallService;
import com.ymttest.common.order.userquery.util.Utils;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.hunter.HunterRelation;
import com.ymttest.database.model.hunter.HunterSettlement;
import com.ymttest.database.model.hunter.HunterSettlementManageFeeDetail;
import com.ymttest.database.model.hunter.HunterSettlementSalesDetail;
import com.ymttest.database.model.hunter.ManageServiceFeeConfig;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.RefundBillPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.hunter.HunterRelationWrapper;
import com.ymttest.database.sqlwapper.hunter.HunterSettlementManageFeeDetailWrapper;
import com.ymttest.database.sqlwapper.hunter.HunterSettlementSalesDetailWrapper;
import com.ymttest.database.sqlwapper.hunter.HunterSettlementWrapper;
import com.ymttest.database.sqlwapper.hunter.ManageServiceFeeConfigWrapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

@Ignore
public class Ts_HunterOrderSettlement {

	private static long userId = Long.valueOf(EnvSetup.getData("BuyUserId"));

	private static OrderShardingWapper database = new OrderShardingWapper();
	HunterRelationWrapper hunterRelationWrapper = new HunterRelationWrapper();
	YmtCatalogsIWapper wrapper = new YmtCatalogsIWapper();
	ManageServiceFeeConfigWrapper manageServiceFeeConfig = new ManageServiceFeeConfigWrapper();

	private List<HunterSettlement> giftBagSalesHunterSettlementList = null;
	private List<HunterSettlement> productSalesHunterSettlementList = null;

	private static BigDecimal taxFeeRate = new BigDecimal("0.97");
	private static String specialProductId = "p2148963";

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分销订单业务验证");
		database.activeDeadCommunicationsLink(database);
	}

	@Before
	public void caseUp() {
		String accountid1;
		try {
			accountid1 = AccountCallServiceV2.getAccountId(20238699);
			AccountCallServiceV2.resetAccount(accountid1, new BigDecimal(
					9000000), new BigDecimal(0));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("hunterOrder");
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 获得总佣金收入
	 * 
	 * @param catalogSettmentDetailMap
	 *            规格的结算信息
	 * 
	 * @return
	 */
	private BigDecimal getTotalSalesCommission(
			Map<String, HunterCatalogSettlementDetailBean> catalogSettmentDetailMap) {
		return catalogSettmentDetailMap.entrySet().stream()
				.map(Map.Entry::getValue).collect(Collectors.toList()).stream()
				.map(HunterCatalogSettlementDetailBean::getSalesCommission)
				.reduce(BigDecimal.ZERO, BigDecimal::add);
	}

	/**
	 * 获得总管理费用
	 * 
	 * @param catalogSettmentDetailMap
	 *            规格的结算信息
	 * 
	 * @return
	 */
	private BigDecimal getTotalManageFee(
			Map<String, HunterCatalogSettlementDetailBean> catalogSettmentDetailMap) {
		return catalogSettmentDetailMap.entrySet().stream()
				.map(Map.Entry::getValue).collect(Collectors.toList()).stream()
				.map(HunterCatalogSettlementDetailBean::getManageFee)
				.reduce(BigDecimal.ZERO, BigDecimal::add);
	}
	
	/**
	 * 判断规格和推手是否存在于规格对应的推手费用信息中
	 * 
	 * @param catalogId 规格
	 * @param hunterId 推手id
	 * @param map
	 *            规格对应的推手费用信息
	 * 
	 * @return
	 */
	private boolean isExistInHunterFeeTypeRelation(String catalogId, long hunterId,
			Map<String, Map<Integer, HunterFeeTypeRelationBean>> map) {

		int i = 0;
		Map<Integer, HunterFeeTypeRelationBean> hunterFeeTypeRelationMap = map
				.get(catalogId);
		
		if (null != hunterFeeTypeRelationMap)
			i = hunterFeeTypeRelationMap
					.entrySet()
					.stream()
					.map(Map.Entry::getValue)
					.collect(Collectors.toList())
					.stream()
					.filter(hunterFeeTypeRelationBean -> hunterFeeTypeRelationBean
							.getHunterId() == hunterId)
					.collect(Collectors.toList()).size();
		else
			return false;
		

		return i == 0 ? false : true;
	}

	/**
	 * 获取管理费用或比例
	 * 
	 * @param serviceFeeType
	 *            （1：互助金 2：伯乐奖）
	 * @param productType
	 * @param currencyHunterLevel
	 * @param parentHunterLevel
	 * 
	 * @return
	 */
	private BigDecimal getManageServiceFee(
			HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean,
			int parentHunterLevel) {
		
		if (hunterCatalogSettlementDetailBean.getCatalogCommission().compareTo(BigDecimal.ZERO) == 0)
			return BigDecimal.ZERO;

		int productType = hunterCatalogSettlementDetailBean.getProductType();
		int childhunterLevel = hunterCatalogSettlementDetailBean
				.getChildHunterLevel();
		int specialType = hunterCatalogSettlementDetailBean.getOrderDetailPo()
				.getProductId().equalsIgnoreCase(specialProductId) ? 1 : 0;

		ManageServiceFeeConfig config = new ManageServiceFeeConfig();

		if (productType == 1) {

			if (specialType == 1)
				config = manageServiceFeeConfig.selectConfigBySpecialType(
						hunterCatalogSettlementDetailBean.getFeeType(),
						specialType, childhunterLevel, parentHunterLevel);
			else
				config = manageServiceFeeConfig
						.selectConfigByTypeAndHunterLevel(
								hunterCatalogSettlementDetailBean.getFeeType(),
								productType, childhunterLevel,
								parentHunterLevel);

			return config.getService_fee_amount();
		}
		else {
			
			if (hunterCatalogSettlementDetailBean.getNewRule()) {
				
				config = manageServiceFeeConfig
						.selectConfigByTypeAndHunterLevel(
								hunterCatalogSettlementDetailBean.getFeeType(),
								0, 0,
								parentHunterLevel);
			} else {

				config = manageServiceFeeConfig
						.selectConfigByTypeAndHunterLevel(
								hunterCatalogSettlementDetailBean.getFeeType(),
								productType, childhunterLevel,
								parentHunterLevel);
			}
			
			
			return config.getService_fee_amount().multiply(new BigDecimal("0.01"));
		}
	}

	/**
	 * 计算优选商品的管理费用
	 * 
	 * @param currencyHunterLevel
	 * @param parentHunterLevel
	 * 
	 * @return
	 */
	@Ignore
	private BigDecimal calOptimizedProductManageFee(int parentHunterLevel,
			HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean) {

		BigDecimal totalCatalogManageFee = BigDecimal.ZERO;
		BigDecimal catalogManageFee = BigDecimal.ZERO;

		OrderDetailPo detailPo = hunterCatalogSettlementDetailBean
				.getOrderDetailPo();
		int currencyHunterLevel = hunterCatalogSettlementDetailBean
				.getChildHunterLevel();
		
		try {

			JSONObject saleCommissionList = new JSONObject(
					hunterCatalogSettlementDetailBean.getSaleCommissionList());

			BigDecimal hunterSaleCommission = new BigDecimal(
					saleCommissionList.optString("1"));
			BigDecimal serviceSaleCommission = new BigDecimal(
					saleCommissionList.optString("2"));
			BigDecimal goldServiceSaleCommission = new BigDecimal(
					saleCommissionList.optString("3"));
			BigDecimal partnerSaleCommission = new BigDecimal(
					saleCommissionList.optString("4"));

			if (currencyHunterLevel == 1 && parentHunterLevel == 2)
				catalogManageFee = serviceSaleCommission
						.subtract(hunterSaleCommission);
			else if (currencyHunterLevel == 1 && parentHunterLevel == 3)
				catalogManageFee = goldServiceSaleCommission
						.subtract(hunterSaleCommission);
			else if (currencyHunterLevel == 1 && parentHunterLevel == 4)
				catalogManageFee = partnerSaleCommission
						.subtract(hunterSaleCommission);
			else if (currencyHunterLevel == 2 && parentHunterLevel == 3)
				catalogManageFee = goldServiceSaleCommission
						.subtract(serviceSaleCommission);
			else if (currencyHunterLevel == 2 && parentHunterLevel == 4)
				catalogManageFee = partnerSaleCommission
						.subtract(serviceSaleCommission);
			else if (currencyHunterLevel == 3 && parentHunterLevel == 4)
				catalogManageFee = partnerSaleCommission
						.subtract(goldServiceSaleCommission);
			else
				catalogManageFee = BigDecimal.ZERO;

			hunterCatalogSettlementDetailBean
					.setSinglePerManageFee(catalogManageFee);
			totalCatalogManageFee = catalogManageFee.multiply(new BigDecimal(
					detailPo.getProductCount()
							- hunterCatalogSettlementDetailBean
									.getRefundCount()));

			return totalCatalogManageFee;

		} catch (JSONException e) {
			Logger.fail(e);

			return BigDecimal.ZERO;
		}
	}

	/**
	 * 获得佣金
	 * 
	 * @param orderId
	 * @param level
	 *            hunter等级
	 * @param HunterCatalogSettlementDetailBean
	 *            推手规格结算明细
	 * @return
	 * @throws InterruptedException
	 */
	private BigDecimal getProductCommision(long orderId, int level,
			HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean)
			throws InterruptedException {

		//制度-新812,商品和优选商品收取的佣金为商品佣金的60%
		
		BigDecimal totalCommision = BigDecimal.ZERO;
		BigDecimal catalogCommission = BigDecimal.ZERO;
		BigDecimal singleCatalogPayableAmount = BigDecimal.ZERO;

		OrderDetailPo orderDetailPo = hunterCatalogSettlementDetailBean
				.getOrderDetailPo();
		int productType = hunterCatalogSettlementDetailBean.getProductType();
		Boolean newRule = hunterCatalogSettlementDetailBean.getNewRule();
		
		String catalogId = orderDetailPo.getCatalogId();
		int productCount = orderDetailPo.getProductCount();
		BigDecimal productPrice = orderDetailPo.getProductPrice();

		RefundBillPo refundBillPo = database
				.selectRefundBillByOrderIdAndCatalogId(orderId, catalogId);
		int refundCount = refundBillPo == null ? 0 : refundBillPo
				.getProductCount();
		String refundBillNo = refundBillPo == null ? null : refundBillPo
				.getRefundBillNo();
		YmtCatalogsI catalogI = wrapper.selectCatalogsByCatalogId(catalogId);
		
		if (productType == 2) {
			if (newRule) {
				
				// 实付金额
				BigDecimal payableAmount = productPrice
						.multiply(new BigDecimal(productCount))
						.subtract(orderDetailPo.getSellerCouponAmount())
						.subtract(orderDetailPo.getYmtCouponAmount());
				BigDecimal totalPrice = productPrice.multiply(new BigDecimal(
						productCount));

				BigDecimal rate = payableAmount.divide(totalPrice, 32,
						RoundingMode.DOWN);
				BigDecimal dividedAmount = catalogI
						.getfQuotePrice()
						.multiply(
								hunterCatalogSettlementDetailBean
										.getSaleTerminalPercent())
						.multiply(rate).setScale(2, RoundingMode.DOWN);
				
				catalogCommission = dividedAmount
						.multiply(hunterCatalogSettlementDetailBean
								.getSaleTerminalPercent());
				singleCatalogPayableAmount = payableAmount.divide(
						new BigDecimal(productCount), 2, RoundingMode.DOWN);

				totalCommision = catalogCommission.multiply(BigDecimal
						.valueOf(productCount - refundCount));
				
				hunterCatalogSettlementDetailBean.setDivided_amount(dividedAmount);
			} else {
				
				// 实付金额
				BigDecimal payableAmount = productPrice
						.multiply(new BigDecimal(productCount))
						.subtract(orderDetailPo.getSellerCouponAmount())
						.subtract(orderDetailPo.getYmtCouponAmount());
				BigDecimal totalPrice = productPrice.multiply(new BigDecimal(
						productCount));

				BigDecimal rate = payableAmount.divide(totalPrice, 32,
						RoundingMode.DOWN);

				catalogCommission = catalogI
						.getSaleCommission()
						.multiply(rate).setScale(2, RoundingMode.DOWN);
				singleCatalogPayableAmount = payableAmount.divide(new BigDecimal(
						productCount), 2, RoundingMode.DOWN);
				
				totalCommision = catalogCommission.multiply(BigDecimal
						.valueOf(productCount - refundCount));
			}
		} else if (productType == 3) {
			if (newRule) {
				
				// 实付金额
				BigDecimal payableAmount = productPrice
						.multiply(new BigDecimal(productCount))
						.subtract(orderDetailPo.getSellerCouponAmount())
						.subtract(orderDetailPo.getYmtCouponAmount());
				BigDecimal totalPrice = productPrice.multiply(new BigDecimal(
						productCount));
				BigDecimal rate = payableAmount.divide(totalPrice, 32,
						RoundingMode.DOWN);
				BigDecimal dividedAmount = catalogI
						.getfQuotePrice()
						.multiply(
								hunterCatalogSettlementDetailBean
										.getSaleTerminalPercent())
						.multiply(rate).setScale(2, RoundingMode.DOWN);

				catalogCommission = dividedAmount.multiply(hunterCatalogSettlementDetailBean.getSaleTerminalPercent());
				singleCatalogPayableAmount = payableAmount.divide(new BigDecimal(
						productCount), 2, RoundingMode.DOWN);
				
				totalCommision = catalogCommission.multiply(BigDecimal
						.valueOf(productCount - refundCount));
				hunterCatalogSettlementDetailBean.setDivided_amount(dividedAmount);
			} else {
				
				String[] commisssionList = catalogI.getSaleCommissions().split(",");

				if (level == 1)
					catalogCommission = new BigDecimal(commisssionList[0]);
				else if (level == 2)
					catalogCommission = new BigDecimal(commisssionList[1]);
				else if (level == 3)
					catalogCommission = new BigDecimal(commisssionList[2]);
				else
					catalogCommission = new BigDecimal(commisssionList[3]);

				singleCatalogPayableAmount = productPrice;
				
				totalCommision = catalogCommission.multiply(BigDecimal
						.valueOf(productCount - refundCount));
			}
		} else {
			
			String[] commisssionList = catalogI.getSaleCommissionPercent()
					.split(",");

			if (level == 1)
				catalogCommission = catalogI.getfQuotePrice()
						.multiply(new BigDecimal(commisssionList[0]))
						.setScale(2, RoundingMode.DOWN);
			else if (level == 2)
				catalogCommission = catalogI.getfQuotePrice()
						.multiply(new BigDecimal(commisssionList[1]))
						.setScale(2, RoundingMode.DOWN);
			else if (level == 3)
				catalogCommission = catalogI.getfQuotePrice()
						.multiply(new BigDecimal(commisssionList[2]))
						.setScale(2, RoundingMode.DOWN);
			else
				catalogCommission = catalogI.getfQuotePrice()
						.multiply(new BigDecimal(commisssionList[3]))
						.setScale(2, RoundingMode.DOWN);

			singleCatalogPayableAmount = productPrice;
			
			totalCommision = catalogCommission.multiply(BigDecimal
					.valueOf(productCount));
			
			hunterCatalogSettlementDetailBean.setDivided_amount(null);
			hunterCatalogSettlementDetailBean.setSaleTerminalPercent(BigDecimal.ONE);
		}

		hunterCatalogSettlementDetailBean.setSalesCommission(totalCommision);
		hunterCatalogSettlementDetailBean.setRefundCount(refundCount);
		hunterCatalogSettlementDetailBean.setRefundNo(refundBillNo);
		hunterCatalogSettlementDetailBean
				.setCatalogCommission(catalogCommission);
		hunterCatalogSettlementDetailBean
				.setPayableAmount(singleCatalogPayableAmount);

		return totalCommision;
	}

	/**
	 * 获得订单商品总金额和SettlementStatus
	 * 
	 * @param orderId
	 * @param needSettlement
	 *            是否发生了结算行为
	 * @return map
	 */
	private Map<String, Object> getSettlementStatusAndProductTotalPriceByOrderId(
			long orderId, boolean needSettlement) {

		Map<String, Object> map = new HashMap<String, Object>();
		OrderPo order = database.selectOrderbyOrderId(orderId);
		List<OrderDetailPo> orderDetailPoList = database
				.selectOrderDetailbyOrderId(orderId);
		List<RefundBillPo> billPoList = database
				.selectRefundBillListByOrderId(orderId);
		BigDecimal totalPrice = order.getTotalPrice();
		int orderStatus = order.getOrderStatus();
		int settlementStatus = 0;
		int productCount = 0;
		int refundCount = 0;
		boolean isSuccess = database.isOrderRefundSuccess(orderId);

		for (OrderDetailPo orderDetail : orderDetailPoList) {

			String catalogId = orderDetail.getCatalogId();

			RefundBillPo refundBillPo = database
					.selectRefundBillByOrderIdAndCatalogId(orderId, catalogId);
			refundCount = refundBillPo == null ? 0 : refundBillPo
					.getProductCount();
			productCount += orderDetail.getProductCount();
			totalPrice = totalPrice.subtract(orderDetail.getProductPrice()
					.multiply(BigDecimal.valueOf(refundCount)));
		}

		/*
		 * 如果发生了结算，部分退款成功或者没有退款单，则预期结算成功:settlementStatus = 1
		 * 如果发生了结算，有退款单，全款退款成功或者退款失败， 则预期结算失败:settlementStatus = 0
		 * 
		 * 如果没有发生结算，有退款单，全部退款完成，则预期无需结算:settlementStatus = 2
		 * 如果没有发生结算，其他情况则:settlementStatus = 0
		 */
		if (needSettlement) {
			
			if (billPoList.size() > 0 && !isSuccess)
				settlementStatus = 0;
			else if (billPoList.size() == 0
					|| (refundCount < productCount || totalPrice
							.compareTo(BigDecimal.ZERO) == 1))
				settlementStatus = 1;
			else
				settlementStatus = 2;

		} else {

			if (orderStatus == 12
					&& (refundCount == productCount || totalPrice
							.compareTo(BigDecimal.ZERO) == 0) && isSuccess)
				settlementStatus = 2;
			else
				settlementStatus = 0;
		}

		map.put("totalPrice", totalPrice);
		map.put("settlementStatus", settlementStatus);

		return map;
	}

	/**
	 * 计算分润的hunter和等级
	 * 
	 * @param hunterId
	 *            推手id（推荐人）
	 * @param productType
	 *            商品类型（1：大礼包商品，2：普通商品，3：优选商品）
	 */
	// 2019-07-11变更，http://172.16.100.247/wangxia/%E5%88%B6%E5%BA%A6/#g=1&p=%E6%96%B0%E5%88%B6%E5%BA%A6_-%E8%BF%9B%E9%98%B6
	private Map<Integer, HunterFeeTypeRelationBean> calManageFeeOfHunter(
			long hunterId, int productType, Boolean newRule) {

		Map<Integer, HunterFeeTypeRelationBean> resultMap = new LinkedHashMap<>();

		int index = 0;

		// 合伙人最大互助奖人数
		int maxPartnerMutuallyNum = 1;
		int partnerMutuallyNum = 0;

		// 合伙人最大伯乐奖人数
		int maxPartnerTalentScoutNum = 1;
		int partnerTalentScoutNum = 0;

		// 金牌服务商最大互助奖人数
		int maxGoldServiceMutuallyNum = 1;
		int goldServiceMutuallyNum = 0;

		// 金牌服务商最大伯乐奖人数
		int maxGoldServiceTalentScoutNum = 1;
		int goldServiceTalentScoutNum = 0;

		// 服务商最大互助奖人数
		int maxServiceMutuallyNum = 1;
		int serviceMutuallyNum = 0;

		// 服务商最大伯乐奖人数
		int maxServiceTalentScoutNum = 1;
		int serviceTalentScoutNum = 0;

		// 优选团商品没有伯乐奖
		// 制度-新812  优选团商品和普通商品分润人数一致
		if (productType == 3 && !newRule) {

			maxPartnerTalentScoutNum = 0;
			maxGoldServiceTalentScoutNum = 0;
			maxServiceTalentScoutNum = 0;
		}

		HunterRelationWrapper hunterRelationWrapper = new HunterRelationWrapper();
		HunterRelation hunterRelation = hunterRelationWrapper
				.selectByPrimaryKey(hunterId);
		
		if (newRule) {

			while (hunterRelation != null) {

				HunterFeeTypeRelationBean hunterFeeTypeRelation = new HunterFeeTypeRelationBean();
				HunterRelation parentHunterRelation = hunterRelationWrapper
						.selectByPrimaryKey(hunterRelation
								.getParent_hunter_id());

				if (hunterRelation.getHunter_level() == 2) {
					if (serviceMutuallyNum < maxServiceMutuallyNum) {

						hunterFeeTypeRelation.setFeeType(1);
						hunterFeeTypeRelation.setHunterId(hunterRelation
								.getHunter_id());
						hunterFeeTypeRelation.setHunterLevel(hunterRelation
								.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						serviceMutuallyNum++;
					} else if (serviceTalentScoutNum < maxServiceTalentScoutNum) {

						hunterFeeTypeRelation.setFeeType(2);
						hunterFeeTypeRelation.setHunterId(hunterRelation
								.getHunter_id());
						hunterFeeTypeRelation.setHunterLevel(hunterRelation
								.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						serviceTalentScoutNum++;
					}
				} else if (hunterRelation.getHunter_level() == 3) {

					if (goldServiceMutuallyNum < maxGoldServiceMutuallyNum) {

						hunterFeeTypeRelation.setFeeType(1);
						hunterFeeTypeRelation.setHunterId(hunterRelation
								.getHunter_id());
						hunterFeeTypeRelation.setHunterLevel(hunterRelation
								.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						goldServiceMutuallyNum++;
					} else if (goldServiceTalentScoutNum < maxGoldServiceTalentScoutNum) {

						hunterFeeTypeRelation.setFeeType(2);
						hunterFeeTypeRelation.setHunterId(hunterRelation
								.getHunter_id());
						hunterFeeTypeRelation.setHunterLevel(hunterRelation
								.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						goldServiceTalentScoutNum++;
					}
				} else if (hunterRelation.getHunter_level() == 4) {

					if (partnerMutuallyNum < maxPartnerMutuallyNum) {

						hunterFeeTypeRelation.setFeeType(1);
						hunterFeeTypeRelation.setHunterId(hunterRelation
								.getHunter_id());
						hunterFeeTypeRelation.setHunterLevel(hunterRelation
								.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						partnerMutuallyNum++;
					} else if (partnerTalentScoutNum < maxPartnerTalentScoutNum) {

						hunterFeeTypeRelation.setFeeType(2);
						hunterFeeTypeRelation.setHunterId(hunterRelation
								.getHunter_id());
						hunterFeeTypeRelation.setHunterLevel(hunterRelation
								.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						partnerTalentScoutNum++;
					}
				}
				
				hunterRelation = parentHunterRelation;
			}
		} else {

			while (hunterRelation.getParent_hunter_id() != 0) {

				HunterFeeTypeRelationBean hunterFeeTypeRelation = new HunterFeeTypeRelationBean();
				HunterRelation parentHunterRelation = hunterRelationWrapper
						.selectByPrimaryKey(hunterRelation
								.getParent_hunter_id());

				int feeType = parentHunterRelation.getHunter_level() == hunterRelation
						.getHunter_level() ? 2 : 1;

				if (parentHunterRelation.getHunter_level() == 2) {
					if (feeType == 1
							&& serviceMutuallyNum < maxServiceMutuallyNum) {

						hunterFeeTypeRelation.setFeeType(feeType);
						hunterFeeTypeRelation.setHunterId(parentHunterRelation
								.getHunter_id());
						hunterFeeTypeRelation
								.setHunterLevel(parentHunterRelation
										.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						serviceMutuallyNum++;
					} else if (feeType == 2
							&& serviceTalentScoutNum < maxServiceTalentScoutNum) {

						hunterFeeTypeRelation.setFeeType(feeType);
						hunterFeeTypeRelation.setHunterId(parentHunterRelation
								.getHunter_id());
						hunterFeeTypeRelation
								.setHunterLevel(parentHunterRelation
										.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						serviceTalentScoutNum++;
					}
				} else if (parentHunterRelation.getHunter_level() == 3) {

					if (feeType == 1
							&& goldServiceMutuallyNum < maxGoldServiceMutuallyNum) {

						hunterFeeTypeRelation.setFeeType(feeType);
						hunterFeeTypeRelation.setHunterId(parentHunterRelation
								.getHunter_id());
						hunterFeeTypeRelation
								.setHunterLevel(parentHunterRelation
										.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						goldServiceMutuallyNum++;
					} else if (feeType == 2
							&& goldServiceTalentScoutNum < maxGoldServiceTalentScoutNum) {

						hunterFeeTypeRelation.setFeeType(feeType);
						hunterFeeTypeRelation.setHunterId(parentHunterRelation
								.getHunter_id());
						hunterFeeTypeRelation
								.setHunterLevel(parentHunterRelation
										.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						goldServiceTalentScoutNum++;
					}
				} else if (parentHunterRelation.getHunter_level() == 4) {

					if (feeType == 1
							&& partnerMutuallyNum < maxPartnerMutuallyNum) {

						hunterFeeTypeRelation.setFeeType(feeType);
						hunterFeeTypeRelation.setHunterId(parentHunterRelation
								.getHunter_id());
						hunterFeeTypeRelation
								.setHunterLevel(parentHunterRelation
										.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						partnerMutuallyNum++;
					} else if (feeType == 2
							&& partnerTalentScoutNum < maxPartnerTalentScoutNum) {

						hunterFeeTypeRelation.setFeeType(feeType);
						hunterFeeTypeRelation.setHunterId(parentHunterRelation
								.getHunter_id());
						hunterFeeTypeRelation
								.setHunterLevel(parentHunterRelation
										.getHunter_level());
						resultMap.put(++index, hunterFeeTypeRelation);

						partnerTalentScoutNum++;
					}
				}

				hunterRelation = parentHunterRelation;
			}
		}
		
		return resultMap;
	}
	
	private BigDecimal getHunterSettlementManageFee(
			Boolean newRule,
			Boolean needSettlement,
			int index,
			int feeType,
			int productCount,
			int refundCount,
			int settlementStatus,
			BigDecimal currentLevelFeeRate,
			int currentHunterLevel,
			BigDecimal balanceRate,
			BigDecimal priorHunterLevelFeeRate,
			BigDecimal singleBaseLine,
			BigDecimal singleManageFee,
			BigDecimal manageFeeRate,
			BigDecimal baseLine,
			BigDecimal manageFee,
			HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean,
			OrderDetailPo orderDetailPo,
			Map<String, HunterCatalogSettlementDetailBean> catalogCommissionDetailMap,
			Map<String, HunterCatalogSettlementDetailBean> catalogManageFeeDetailMap) {
		
		if (index == 1 && feeType == 1) {

			if (newRule) {
				
				singleBaseLine = catalogCommissionDetailMap.get(
						orderDetailPo.getCatalogId()).getDivided_amount().multiply(manageFeeRate);
				singleManageFee = singleBaseLine
						.multiply(balanceRate).setScale(2, RoundingMode.DOWN);
			} else {
				
				singleBaseLine = hunterCatalogSettlementDetailBean
						.getCatalogCommission();
				singleManageFee = singleBaseLine
						.multiply(currentLevelFeeRate);
			}
			
			baseLine = singleBaseLine.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));
			manageFee = singleManageFee.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));

			hunterCatalogSettlementDetailBean
					.setSinglePerBaseLineFee(singleBaseLine);
			
			singleBaseLine = singleManageFee;

		} else if (index == 1 && feeType == 2) {

			if (newRule) {
				
				singleBaseLine = catalogCommissionDetailMap.get(
						orderDetailPo.getCatalogId()).getDivided_amount().multiply(manageFeeRate);
				singleManageFee = singleBaseLine
						.multiply(balanceRate).setScale(2, RoundingMode.DOWN);
			} else {
				
				singleBaseLine = hunterCatalogSettlementDetailBean
						.getCatalogCommission()
						.multiply(new BigDecimal("0.20"))
						.setScale(2, RoundingMode.DOWN);
				singleManageFee = singleBaseLine
						.multiply(currentLevelFeeRate);
			}
			
			baseLine = singleBaseLine.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));
			manageFee = singleManageFee.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));

			hunterCatalogSettlementDetailBean
					.setSinglePerBaseLineFee(singleBaseLine);

		} else if (feeType == 1) {

			if (newRule) {
				
				singleBaseLine = catalogCommissionDetailMap.get(
						orderDetailPo.getCatalogId()).getDivided_amount().multiply(manageFeeRate);
				singleManageFee = singleBaseLine
						.multiply(balanceRate).setScale(2, RoundingMode.DOWN);
			} else {
				
				singleManageFee = singleBaseLine.multiply(currentLevelFeeRate)
						.setScale(2, RoundingMode.DOWN);
			}
			
			baseLine = singleBaseLine.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));
			manageFee = singleManageFee.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));

			hunterCatalogSettlementDetailBean
					.setSinglePerBaseLineFee(singleBaseLine);
			
			singleBaseLine = singleManageFee;
		} else {

			if (newRule) {
				
				singleBaseLine = catalogCommissionDetailMap.get(
						orderDetailPo.getCatalogId()).getDivided_amount().multiply(manageFeeRate);
				singleManageFee = singleBaseLine
						.multiply(balanceRate).setScale(2, RoundingMode.DOWN);
			} else {
				
				singleManageFee = singleBaseLine.multiply(
						currentLevelFeeRate).setScale(2,
						RoundingMode.DOWN);
			}
			
			baseLine = singleBaseLine.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));
			manageFee = singleManageFee.multiply(new BigDecimal(
					productCount - refundCount).setScale(2,
					RoundingMode.DOWN));
			
			hunterCatalogSettlementDetailBean
					.setSinglePerBaseLineFee(singleBaseLine);
		}
		
		if (null != hunterCatalogSettlementDetailBean.getRefundNo()
				&& needSettlement
				&& orderDetailPo.getProductCount() == hunterCatalogSettlementDetailBean
						.getRefundCount())
			settlementStatus = 0;

		hunterCatalogSettlementDetailBean.setBaseLine(baseLine);
		hunterCatalogSettlementDetailBean
				.setSinglePerManageFee(singleManageFee);
		hunterCatalogSettlementDetailBean
				.setCurrentLevelFeeRate(newRule ? balanceRate : currentLevelFeeRate);

		hunterCatalogSettlementDetailBean.setManageFee(manageFee);

		catalogManageFeeDetailMap.put(orderDetailPo.getCatalogId(),
				hunterCatalogSettlementDetailBean);
		
		return singleBaseLine;
	}

	/**
	 * 验证数据库
	 * 
	 * @param orderId
	 * @param hunterId
	 * @param hunterOrderType
	 *            订单类型（1：大礼包订单，2：普通订单(包括普通商品或者优选团商品)）
	 * @param needSettlement
	 *            是否需要结算
	 * @throws InterruptedException
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	private void verifyDb(long orderId, long hunterId, int hunterOrderType,
			boolean needSettlement) throws InterruptedException,
			ClientProtocolException, IOException {

		Thread.sleep(3000);

		Logger.comment("开始验证tradingsettlement数据库: orderId为" + orderId);
		
		if (needSettlement)
			HunterCallService.doCommissionSettlement();

		// 校验结算表相关数据
		this.verifyHunterSettlement(orderId, hunterId, hunterOrderType,
				needSettlement);

	}

	/**
	 * 验证HunterSettlement表
	 * 
	 * @param orderId
	 * @param hunterId
	 * @param hunterOrderType
	 *            订单类型（1：大礼包订单，2：普通订单）
	 * @param needSettlement
	 *            是否需要结算
	 * @throws InterruptedException
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	private void verifyHunterSettlement(long orderId, long hunterId,
			int hunterOrderType, boolean needSettlement)
			throws InterruptedException, ClientProtocolException, IOException {

		Logger.comment("开始验证HunterSettlement表");

		HunterSettlementWrapper hunterSettlementWrapper = new HunterSettlementWrapper();
		AccountWapper accountWapper = new AccountWapper();

		BigDecimal totalSalesCommission = BigDecimal.ZERO;

		OrderPo order = database.selectOrderbyOrderId(orderId);
		List<OrderDetailPo> orderDetailPoList = database
				.selectOrderDetailbyOrderId(orderId);

		Map<String, Object> map = this
				.getSettlementStatusAndProductTotalPriceByOrderId(orderId,
						needSettlement);
		BigDecimal totalProductPrice = (BigDecimal) map.get("totalPrice");
		int settlementStatus = (Integer) map.get("settlementStatus");

		Map<String, HunterCatalogSettlementDetailBean> catalogCommissionDetailMap = new HashMap<>();

		HunterRelation hunterRelation = hunterRelationWrapper
				.selectByPrimaryKey(hunterId);

		if (needSettlement) {

			hunterSettlementWrapper.updateExpectSettlementTimeByOrderId(
					YMTDateUtil.getBeforeOrNextDate(-1), orderId);
			HunterCallService.doCommissionSettlement();
		}

		List<HunterSettlement> hunterSettlementList = hunterSettlementWrapper
				.selectByOrderId(orderId);

		// 1为大礼包，type只有20，21；2为普通商品type只有22，23
		if (hunterOrderType == 1) {

			// 大礼包销售佣金结算列表
			this.giftBagSalesHunterSettlementList = hunterSettlementList
					.stream()
					.filter(hunterSettlement -> hunterSettlement
							.getSettlement_type() == 20)
					.collect(Collectors.toList());
			// 大礼包管理费结算列表
			List<HunterSettlement> giftBagManageHunterSettlementList = hunterSettlementList
					.stream()
					.filter(hunterSettlement -> hunterSettlement
							.getSettlement_type() == 21)
					.collect(Collectors.toList());

			// 验证大礼包销售佣金结算列表
			for (HunterSettlement hunterSettlement : giftBagSalesHunterSettlementList) {

				Logger.comment("开始验证" + hunterSettlement.getId());

				HunterSettlement expectHuntersettlement = new HunterSettlement();
				hunterRelation = hunterRelationWrapper
						.selectByPrimaryKey(hunterId);
				int hunterLevel = hunterRelation.getHunter_level();

				for (OrderDetailPo orderDetailPo : orderDetailPoList) {

					HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean = new HunterCatalogSettlementDetailBean();

					hunterCatalogSettlementDetailBean
							.setOrderDetailPo(orderDetailPo);
					hunterCatalogSettlementDetailBean.setProductType(1);
					
					this.getProductCommision(orderId, hunterLevel,
							hunterCatalogSettlementDetailBean);

					hunterCatalogSettlementDetailBean
							.setOrderDetailPo(orderDetailPo);
					hunterCatalogSettlementDetailBean.setOrderId(orderId);

					catalogCommissionDetailMap.put(orderDetailPo.getCatalogId(),
							hunterCatalogSettlementDetailBean);
				}

				// 获取总佣金收入
				totalSalesCommission = this
						.getTotalSalesCommission(catalogCommissionDetailMap);
				
				if (hunterRelation.getStatus() == 2)
					expectHuntersettlement.setSettlement_status(2);
				else if (totalSalesCommission.compareTo(BigDecimal.ZERO) == 0)
					expectHuntersettlement.setSettlement_status(1);
				else
					expectHuntersettlement
							.setSettlement_status(settlementStatus);

				expectHuntersettlement.setBiz_no(String.valueOf(orderId));
				expectHuntersettlement.setSettlement_type(20);
				expectHuntersettlement.setOrder_id(orderId);
				expectHuntersettlement.setHunter_id(hunterId);
				expectHuntersettlement.setHunter_level(hunterLevel);
				expectHuntersettlement.setTotal_amount(totalSalesCommission);
				expectHuntersettlement.setTotal_product_price(order
						.getTotalPrice());
				
				if (totalSalesCommission.compareTo(BigDecimal.ZERO) == 0)
					expectHuntersettlement.setRemark("结算金额为0，已结算");
				else if (expectHuntersettlement.getSettlement_status() == 2)
					expectHuntersettlement.setRemark("订单取消，作废");
				else
					expectHuntersettlement.setRemark(null);

				DataUtil.verify(expectHuntersettlement.getBiz_no(),
						hunterSettlement.getBiz_no(), "验证Biz_no");
				DataUtil.verify(expectHuntersettlement.getSettlement_type(),
						hunterSettlement.getSettlement_type(),
						"验证Settlement_type");
				DataUtil.verify(expectHuntersettlement.getRemark(),
						hunterSettlement.getRemark(),
						"验证Remark");
				DataUtil.verify(expectHuntersettlement.getOrder_id(),
						hunterSettlement.getOrder_id(), "验证Order_id");
				DataUtil.verify(expectHuntersettlement.getHunter_id(),
						hunterSettlement.getHunter_id(), "验证Hunter_id");
				DataUtil.verify(expectHuntersettlement.getSettlement_status(),
						hunterSettlement.getSettlement_status(),
						"验证Settlement_status");
				DataUtil.verify(expectHuntersettlement.getHunter_level(),
						hunterSettlement.getHunter_level(), "验证Hunter_level");
				DataUtil.verify(expectHuntersettlement.getTotal_amount(),
						hunterSettlement.getTotal_amount(), "验证Total_amount");
				DataUtil.verify(
						expectHuntersettlement.getTotal_product_price(),
						hunterSettlement.getTotal_product_price(),
						"验证Total_product_price");

				// 验证销售佣金明细
				this.verifyHunterSettlementSalesDetail(
						hunterSettlement.getId(), catalogCommissionDetailMap);
			}

			// 计算获得管理费的人
			Map<Integer, HunterFeeTypeRelationBean> manageMap = this
					.calManageFeeOfHunter(hunterId, 1, false);

			Iterator<Entry<Integer, HunterFeeTypeRelationBean>> iter = manageMap
					.entrySet().iterator();
			long currentHunterId = 0;
			int currentHunterLevel = 0;
			int feeType = 0;

			DataUtil.verify(manageMap.size(),
					giftBagManageHunterSettlementList.size(), "验证收取管理费人数");

			// 验证大礼包销售管理费结算列表
			for (HunterSettlement hunterSettlement : giftBagManageHunterSettlementList) {

				Logger.comment("开始验证" + hunterSettlement.getId());

				if (iter.hasNext()) {
					Entry<Integer, HunterFeeTypeRelationBean> entry = iter
							.next();

					HunterFeeTypeRelationBean bean = entry.getValue();

					currentHunterId = bean.getHunterId();
					currentHunterLevel = bean.getHunterLevel();
					feeType = bean.getFeeType();
				}

				HunterSettlement expectHuntersettlement = new HunterSettlement();
				hunterRelation = hunterRelationWrapper
						.selectByPrimaryKey(hunterId);

				int hunterLevel = hunterRelation.getHunter_level();

				for (OrderDetailPo orderDetailPo : orderDetailPoList) {

					if (catalogCommissionDetailMap.containsKey(orderDetailPo
							.getCatalogId())) {

						HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean = catalogCommissionDetailMap
								.get(orderDetailPo.getCatalogId());

						hunterCatalogSettlementDetailBean.setFeeType(feeType);
						hunterCatalogSettlementDetailBean
								.setChildHunterId(hunterId);
						hunterCatalogSettlementDetailBean
								.setChildHunterLevel(hunterLevel);

						BigDecimal manageFee = this.getManageServiceFee(
								hunterCatalogSettlementDetailBean,
								currentHunterLevel);

						hunterCatalogSettlementDetailBean
								.setManageFee(manageFee);

						catalogCommissionDetailMap.put(
								orderDetailPo.getCatalogId(),
								hunterCatalogSettlementDetailBean);
					}
				}

				// 获取总管理费
				BigDecimal totalManageFee = this
						.getTotalManageFee(catalogCommissionDetailMap);
				
				if (hunterRelation.getStatus() == 2)
					expectHuntersettlement.setSettlement_status(2);
				else if (totalManageFee.compareTo(BigDecimal.ZERO) == 0)
					expectHuntersettlement.setSettlement_status(1);
				else
					expectHuntersettlement
							.setSettlement_status(settlementStatus);
				
				if (totalSalesCommission.compareTo(BigDecimal.ZERO) == 0)
					expectHuntersettlement.setRemark("结算金额为0，已结算");
				else if (expectHuntersettlement.getSettlement_status() == 2)
					expectHuntersettlement.setRemark("订单取消，作废");
				else
					expectHuntersettlement.setRemark(null);

				expectHuntersettlement
						.setBiz_no(giftBagSalesHunterSettlementList.get(0)
								.getId());
				expectHuntersettlement.setSettlement_type(21);
				expectHuntersettlement.setOrder_id(orderId);
				expectHuntersettlement.setHunter_id(currentHunterId);
				expectHuntersettlement.setHunter_level(currentHunterLevel);
				expectHuntersettlement.setTotal_amount(totalManageFee.multiply(
						taxFeeRate).setScale(2));
				expectHuntersettlement.setTotal_product_price(order
						.getTotalPrice());
				
				DataUtil.verify(expectHuntersettlement.getBiz_no(),
						hunterSettlement.getBiz_no(), "验证Biz_no");
				DataUtil.verify(expectHuntersettlement.getSettlement_type(),
						hunterSettlement.getSettlement_type(),
						"验证Settlement_type");
				DataUtil.verify(expectHuntersettlement.getRemark(),
						hunterSettlement.getRemark(),
						"验证Remark");
				DataUtil.verify(expectHuntersettlement.getOrder_id(),
						hunterSettlement.getOrder_id(), "验证Order_id");
				DataUtil.verify(expectHuntersettlement.getSettlement_status(),
						hunterSettlement.getSettlement_status(),
						"验证Settlement_status");
				DataUtil.verify(expectHuntersettlement.getHunter_id(),
						hunterSettlement.getHunter_id(), "验证Hunter_id");
				DataUtil.verify(expectHuntersettlement.getHunter_level(),
						hunterSettlement.getHunter_level(), "验证Hunter_level");
				DataUtil.verify(expectHuntersettlement.getTotal_amount(),
						hunterSettlement.getTotal_amount(), "验证Total_amount");
				DataUtil.verify(
						expectHuntersettlement.getTotal_product_price(),
						hunterSettlement.getTotal_product_price(),
						"验证Total_product_price");

				this.verifyHunterSettlementManageFeeDetail(
						hunterSettlement.getId(), hunterOrderType,
						catalogCommissionDetailMap);

				if (needSettlement
						&& hunterSettlement.getSettlement_status() == 1 && totalManageFee.compareTo(BigDecimal.ZERO) != 0) {

					BigDecimal amount = accountWapper
							.selectAccountEntry(
									hunterSettlement.getHunter_id().intValue(),
									String.valueOf(orderId), 32).get(0)
							.getAmount();

					DataUtil.verify(amount, hunterSettlement.getTotal_amount(),
							"验证accountEntry的amount");
				}

				if (feeType == 1)
					hunterId = currentHunterId;
			}
		} else {

			// 普通订单销售佣金结算列表
			this.productSalesHunterSettlementList = hunterSettlementList
					.stream()
					.filter(hunterSettlement -> hunterSettlement
							.getSettlement_type() == 22)
					.collect(Collectors.toList());
			// 普通订单管理费结算列表
			List<HunterSettlement> productManageHunterSettlementList = hunterSettlementList
					.stream()
					.filter(hunterSettlement -> hunterSettlement
							.getSettlement_type() == 23
							|| hunterSettlement.getSettlement_type() == 30)
					.sorted(Comparator.comparing(HunterSettlement::getHunter_level))
					.collect(Collectors.toList());

			// 根据商品类型统计收管理费的hunter
			Map<String, Map<Integer, HunterFeeTypeRelationBean>> allCommonProductManageMap = new HashMap<>();
			Map<String, Map<Integer, HunterFeeTypeRelationBean>> allOptimizeProductManageMap = new HashMap<>();
			
			//只要有一个规格为true，即整个订单为true
			Boolean newRule = false;

			// 验证普通订单销售佣金结算列表
			for (HunterSettlement hunterSettlement : productSalesHunterSettlementList) {

				Logger.comment("开始验证" + hunterSettlement.getId());

				HunterSettlement expectHuntersettlement = new HunterSettlement();
				hunterRelation = hunterRelationWrapper
						.selectByPrimaryKey(hunterId);

				int hunterLevel = hunterRelation.getHunter_level();

				for (OrderDetailPo orderDetailPo : orderDetailPoList) {

					HashMap<String, Object> catalogCommissionsMap = HunterCallService
							.getCatalogCommissions(orderDetailPo
									.getCatalogId());
					HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean = new HunterCatalogSettlementDetailBean();
					
					int giftType = Integer.valueOf(catalogCommissionsMap.get(
							"giftType").toString());
					newRule = (Boolean) catalogCommissionsMap.get(
							"newRule");
					BigDecimal saleTerminalPercent = (BigDecimal) catalogCommissionsMap.get(
							"saleTerminalPercent");
					
					hunterCatalogSettlementDetailBean
							.setOrderDetailPo(orderDetailPo);
					hunterCatalogSettlementDetailBean.setOrderId(orderId);
					hunterCatalogSettlementDetailBean.setNewRule(newRule);
					hunterCatalogSettlementDetailBean.setSaleTerminalPercent(saleTerminalPercent);
					
					if (giftType == 0) {

						hunterCatalogSettlementDetailBean.setProductType(2);
						allCommonProductManageMap.put(
								orderDetailPo.getCatalogId(),
								this.calManageFeeOfHunter(hunterId, 2, newRule));
					} else {
						
						hunterCatalogSettlementDetailBean.setProductType(3);
						allOptimizeProductManageMap.put(
								orderDetailPo.getCatalogId(),
								this.calManageFeeOfHunter(hunterId, 3, newRule));
						if (!newRule) {
							
							hunterCatalogSettlementDetailBean
									.setSaleCommissionList(catalogCommissionsMap
											.get("saleCommissionList")
											.toString());
						}
					}
					
					this.getProductCommision(orderId, hunterLevel,
							hunterCatalogSettlementDetailBean);
					
					if (null != hunterCatalogSettlementDetailBean.getRefundNo()
							&& needSettlement
							&& orderDetailPo.getProductCount() == hunterCatalogSettlementDetailBean
									.getRefundCount())
						settlementStatus = 0;

					catalogCommissionDetailMap.put(orderDetailPo.getCatalogId(),
							hunterCatalogSettlementDetailBean);
				}

				// 获取总佣金收入
				totalSalesCommission = this
						.getTotalSalesCommission(catalogCommissionDetailMap);

				if (settlementStatus == 2)
					expectHuntersettlement.setRemark("订单取消，作废");

				if (hunterRelation.getStatus() == 2)
					settlementStatus = 2;

				expectHuntersettlement.setSettlement_status(settlementStatus);
				expectHuntersettlement.setBiz_no(String.valueOf(orderId));
				expectHuntersettlement.setSettlement_type(22);
				expectHuntersettlement.setOrder_id(orderId);
				expectHuntersettlement.setHunter_id(hunterId);
				expectHuntersettlement.setHunter_level(hunterLevel);
				expectHuntersettlement.setTotal_amount(totalSalesCommission);
				expectHuntersettlement
						.setTotal_product_price(totalProductPrice);

				DataUtil.verify(expectHuntersettlement.getBiz_no(),
						hunterSettlement.getBiz_no(), "验证Biz_no");
				DataUtil.verify(expectHuntersettlement.getSettlement_type(),
						hunterSettlement.getSettlement_type(),
						"验证Settlement_type");
				DataUtil.verify(expectHuntersettlement.getOrder_id(),
						hunterSettlement.getOrder_id(), "验证Order_id");
				DataUtil.verify(expectHuntersettlement.getHunter_id(),
						hunterSettlement.getHunter_id(), "验证Hunter_id");
				DataUtil.verify(expectHuntersettlement.getHunter_level(),
						hunterSettlement.getHunter_level(), "验证Hunter_level");
				DataUtil.verify(expectHuntersettlement.getTotal_amount(),
						hunterSettlement.getTotal_amount(), "验证Total_amount");
				DataUtil.verify(expectHuntersettlement.getSettlement_status(),
						hunterSettlement.getSettlement_status(),
						"验证Settlement_status");
				DataUtil.verify(
						expectHuntersettlement.getTotal_product_price(),
						hunterSettlement.getTotal_product_price(),
						"验证Total_product_price");
				DataUtil.verify(expectHuntersettlement.getRemark(),
						hunterSettlement.getRemark(), "验证Remark");

				this.verifyHunterSettlementSalesDetail(
						hunterSettlement.getId(), catalogCommissionDetailMap);
			}

			long currentHunterId = 0;
			int currentHunterLevel = 0;
			int feeType = 0;
			int index = 0;
			
			BigDecimal baseLine = BigDecimal.ZERO;
			BigDecimal singleBaseLine = BigDecimal.ZERO;
			BigDecimal singleManageFee = BigDecimal.ZERO;
			BigDecimal priorHunterLevelFeeRate = BigDecimal.ZERO;
			
			BigDecimal currentLevelFeeRate = BigDecimal.ZERO;

			BigDecimal totalProductSalesManageFee = BigDecimal.ZERO;

			Map<Integer, HunterFeeTypeRelationBean> commonManageMap = new HashMap<>();

			// 同一个订单，如果只有优选商品，则用优选商品的manageMap，否则用普通商品的manageMap
			if (allCommonProductManageMap.size() == 0) {

				Iterator<Entry<String, Map<Integer, HunterFeeTypeRelationBean>>> iter = allOptimizeProductManageMap
						.entrySet().iterator();

				if (iter.hasNext()) {
					Entry<String, Map<Integer, HunterFeeTypeRelationBean>> entry = iter
							.next();
					commonManageMap = entry.getValue();
				}
			} else {

				Iterator<Entry<String, Map<Integer, HunterFeeTypeRelationBean>>> iter = allCommonProductManageMap
						.entrySet().iterator();

				if (iter.hasNext()) {
					Entry<String, Map<Integer, HunterFeeTypeRelationBean>> entry = iter
							.next();
					commonManageMap = entry.getValue();
				}
			}
			
			DataUtil.verify(commonManageMap.size(),
					productManageHunterSettlementList.size(), "验证收取管理费人数");

			Iterator<Entry<Integer, HunterFeeTypeRelationBean>> iter = commonManageMap
					.entrySet().iterator();

			// 验证普通订单销售管理费
			for (HunterSettlement hunterSettlement : productManageHunterSettlementList) {

				Logger.comment("开始验证" + hunterSettlement.getId());
				
				Map<String, HunterCatalogSettlementDetailBean> catalogManageFeeDetailMap = new HashMap<>();

				if (iter.hasNext()) {
					Entry<Integer, HunterFeeTypeRelationBean> entry = iter
							.next();

					HunterFeeTypeRelationBean bean = entry.getValue();

					index = entry.getKey();
					currentHunterId = bean.getHunterId();
					currentHunterLevel = bean.getHunterLevel();
					feeType = bean.getFeeType();
				}

				HunterSettlement expectHuntersettlement = new HunterSettlement();
				hunterRelation = hunterRelationWrapper
						.selectByPrimaryKey(hunterId);
				
				int hunterLevel = hunterRelation.getHunter_level();

				for (OrderDetailPo orderDetailPo : orderDetailPoList) {

					BigDecimal manageFee = BigDecimal.ZERO;
					BigDecimal balanceRate = BigDecimal.ZERO;
					
					int productCount = orderDetailPo.getProductCount();
					int refundCount = catalogCommissionDetailMap.get(
							orderDetailPo.getCatalogId()).getRefundCount();
					BigDecimal manageFeeRate = BigDecimal.ONE.subtract(Utils
							.zeroIfNull(catalogCommissionDetailMap.get(
									orderDetailPo.getCatalogId())
									.getSaleTerminalPercent()));

					HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean = new HunterCatalogSettlementDetailBean();

					hunterCatalogSettlementDetailBean
							.setFeeType(catalogCommissionDetailMap.get(
									orderDetailPo.getCatalogId()).getFeeType());
					hunterCatalogSettlementDetailBean
							.setOrderDetailPo(orderDetailPo);
					hunterCatalogSettlementDetailBean
							.setSaleCommissionList(catalogCommissionDetailMap
									.get(orderDetailPo.getCatalogId())
									.getSaleCommissionList());
					hunterCatalogSettlementDetailBean
							.setSalesCommission(catalogCommissionDetailMap.get(
									orderDetailPo.getCatalogId())
									.getSalesCommission());
					hunterCatalogSettlementDetailBean
							.setCatalogCommission(catalogCommissionDetailMap
									.get(orderDetailPo.getCatalogId())
									.getCatalogCommission());
					hunterCatalogSettlementDetailBean
							.setRefundCount(refundCount);
					hunterCatalogSettlementDetailBean.setOrderId(orderId);
					hunterCatalogSettlementDetailBean
							.setChildHunterId(hunterId);
					hunterCatalogSettlementDetailBean
							.setChildHunterLevel(hunterLevel);
					hunterCatalogSettlementDetailBean.setFeeType(feeType);
					hunterCatalogSettlementDetailBean.setNewRule(newRule);
					
					if (this.isExistInHunterFeeTypeRelation(
							orderDetailPo.getCatalogId(), currentHunterId,
							allOptimizeProductManageMap)) {
						
						hunterCatalogSettlementDetailBean.setProductType(3);
						
						if (hunterCatalogSettlementDetailBean.getNewRule()) {
							
							currentLevelFeeRate = this.getManageServiceFee(
									hunterCatalogSettlementDetailBean,
									currentHunterLevel);
							
							if (hunterCatalogSettlementDetailBean.getNewRule()) {
								
								balanceRate = currentLevelFeeRate.subtract(priorHunterLevelFeeRate);
							}
							
							getHunterSettlementManageFee(newRule, needSettlement,
									index, feeType, productCount, refundCount,
									settlementStatus, currentLevelFeeRate,
									currentHunterLevel, balanceRate,
									priorHunterLevelFeeRate, singleBaseLine,
									singleManageFee, manageFeeRate, baseLine,
									manageFee, hunterCatalogSettlementDetailBean,
									orderDetailPo, catalogCommissionDetailMap,
									catalogManageFeeDetailMap);
						} else {
							
							manageFee = this.calOptimizedProductManageFee(
									currentHunterLevel,
									hunterCatalogSettlementDetailBean);

							hunterCatalogSettlementDetailBean
									.setManageFee(manageFee);

							catalogManageFeeDetailMap.put(
									orderDetailPo.getCatalogId(),
									hunterCatalogSettlementDetailBean);
						}
					} else if (this.isExistInHunterFeeTypeRelation(
							orderDetailPo.getCatalogId(), currentHunterId,
							allCommonProductManageMap)) {
						
						hunterCatalogSettlementDetailBean.setProductType(2);
						currentLevelFeeRate = this.getManageServiceFee(
								hunterCatalogSettlementDetailBean,
								currentHunterLevel);
						
						if (hunterCatalogSettlementDetailBean.getNewRule()) {
							
							balanceRate = currentLevelFeeRate.subtract(priorHunterLevelFeeRate);
						}
						
						singleBaseLine = getHunterSettlementManageFee(newRule, needSettlement,
								index, feeType, productCount, refundCount,
								settlementStatus, currentLevelFeeRate,
								currentHunterLevel, balanceRate,
								priorHunterLevelFeeRate, singleBaseLine,
								singleManageFee, manageFeeRate, baseLine,
								manageFee, hunterCatalogSettlementDetailBean,
								orderDetailPo, catalogCommissionDetailMap,
								catalogManageFeeDetailMap);
					}
				}

				priorHunterLevelFeeRate = currentLevelFeeRate;
				BigDecimal totalManageFee = this
						.getTotalManageFee(catalogManageFeeDetailMap);

				if (settlementStatus == 2)
					expectHuntersettlement.setRemark("订单取消，作废");

				if (hunterRelation.getStatus() == 2)
					settlementStatus = 2;

				expectHuntersettlement.setSettlement_status(settlementStatus);
				expectHuntersettlement
						.setBiz_no(productSalesHunterSettlementList.get(0)
								.getId());
				
				expectHuntersettlement.setSettlement_type(23);

				expectHuntersettlement.setOrder_id(orderId);
				expectHuntersettlement.setHunter_id(currentHunterId);
				expectHuntersettlement.setHunter_level(currentHunterLevel);
				expectHuntersettlement.setTotal_amount(totalManageFee.multiply(
						taxFeeRate).setScale(2, RoundingMode.DOWN));
				expectHuntersettlement
						.setTotal_product_price(totalProductPrice);

				DataUtil.verify(expectHuntersettlement.getBiz_no(),
						hunterSettlement.getBiz_no(), "验证Biz_no");
				DataUtil.verify(expectHuntersettlement.getSettlement_type(),
						hunterSettlement.getSettlement_type(),
						"验证Settlement_type");
				DataUtil.verify(expectHuntersettlement.getOrder_id(),
						hunterSettlement.getOrder_id(), "验证Order_id");
				DataUtil.verify(expectHuntersettlement.getHunter_id(),
						hunterSettlement.getHunter_id(), "验证Hunter_id");
				DataUtil.verify(expectHuntersettlement.getHunter_level(),
						hunterSettlement.getHunter_level(), "验证Hunter_level");
				DataUtil.verify(expectHuntersettlement.getTotal_amount(),
						hunterSettlement.getTotal_amount(), "验证Total_amount");
				DataUtil.verify(expectHuntersettlement.getSettlement_status(),
						hunterSettlement.getSettlement_status(),
						"验证Settlement_status");
				DataUtil.verify(
						expectHuntersettlement.getTotal_product_price(),
						hunterSettlement.getTotal_product_price(),
						"验证Total_product_price");

				if (needSettlement
						&& hunterSettlement.getSettlement_status() == 1) {

						totalProductSalesManageFee = accountWapper
								.selectAccountEntry(
										hunterSettlement.getHunter_id()
												.intValue(),
										String.valueOf(orderId), 32).get(0)
								.getAmount();

					DataUtil.verify(totalProductSalesManageFee,
							hunterSettlement.getTotal_amount(),
							"验证accountEntry的amount");
				}

				this.verifyHunterSettlementManageFeeDetail(
						hunterSettlement.getId(), hunterOrderType,
						catalogManageFeeDetailMap);
				
				if (newRule)
					hunterId = currentHunterId;
				else {
					if (feeType == 1)
						hunterId = currentHunterId;
				}
			}
		}
	}

	/**
	 * 校验HunterSettlementManageFeeDetail
	 * 
	 * @param orderId
	 * @param catalogSettmentDetailMap
	 *            规格结算明细
	 * @throws InterruptedException
	 */
	private void verifyHunterSettlementManageFeeDetail(
			String settlementId,
			int hunterOrderType,
			Map<String, HunterCatalogSettlementDetailBean> catalogSettmentDetailMap)
			throws InterruptedException {

		Logger.comment(String.format(
				"开始验证HunterSettlementManageFeeDetail表, %s管理费明细", settlementId));

		HunterSettlementManageFeeDetailWrapper hunterSettlementManageFeeDetailWrapper = new HunterSettlementManageFeeDetailWrapper();
		Iterator<Entry<String, HunterCatalogSettlementDetailBean>> iter = catalogSettmentDetailMap
				.entrySet().iterator();

		if (hunterOrderType == 1) {
			while (iter.hasNext()) {

				Entry<String, HunterCatalogSettlementDetailBean> entry = iter
						.next();
				HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean = entry
						.getValue();
				long childHunterId = hunterCatalogSettlementDetailBean
						.getChildHunterId();
				BigDecimal manageFee = hunterCatalogSettlementDetailBean
						.getManageFee();

				Logger.comment(String.format("开始验证settlementId：%s",
						settlementId));

				// 大礼包商品管理费明细不使用cataloId查询
				HunterSettlementManageFeeDetail actualPo = hunterSettlementManageFeeDetailWrapper
						.selectBySettlementId(settlementId).get(0);

				HunterSettlementManageFeeDetail expectPo = new HunterSettlementManageFeeDetail();

				expectPo.setSettlement_id(settlementId);
				expectPo.setGift_bag_amount(manageFee);
				expectPo.setTotal_amount(manageFee.multiply(taxFeeRate)
						.setScale(2));
				expectPo.setSales_commission_amount(hunterCatalogSettlementDetailBean
						.getSalesCommission());
				expectPo.setChild_hunter_level(hunterCatalogSettlementDetailBean
						.getChildHunterLevel());
				expectPo.setChild_hunter_id(childHunterId);
				expectPo.setFee_type(hunterCatalogSettlementDetailBean
						.getFeeType());
				expectPo.setProduct_type(hunterCatalogSettlementDetailBean
						.getProductType());
				expectPo.setFee_tax(BigDecimal.ONE.subtract(taxFeeRate));
				expectPo.setOrder_id(hunterCatalogSettlementDetailBean.getOrderId());

				DataUtil.verify(expectPo.getSettlement_id(),
						actualPo.getSettlement_id(), "验证Settlement_id");
				DataUtil.verify(expectPo.getGift_bag_amount(),
						actualPo.getGift_bag_amount(), "验证Gift_bag_amount");
				DataUtil.verify(expectPo.getTotal_amount(),
						actualPo.getTotal_amount(), "验证Total_amount");
				DataUtil.verify(expectPo.getSales_commission_amount(),
						actualPo.getSales_commission_amount(),
						"验证Sales_commission_amount");
				DataUtil.verify(expectPo.getChild_hunter_id(),
						actualPo.getChild_hunter_id(),
						"验证Child_hunter_id");
				DataUtil.verify(expectPo.getChild_hunter_level(),
						actualPo.getChild_hunter_level(),
						"验证Child_hunter_level");
				DataUtil.verify(expectPo.getFee_type(), actualPo.getFee_type(),
						"验证Fee_type");
				DataUtil.verify(expectPo.getProduct_type(),
						actualPo.getProduct_type(), "验证Product_type");
				DataUtil.verify(expectPo.getFee_tax(), actualPo.getFee_tax(),
						"验证Fee_tax");
				DataUtil.verify(expectPo.getOrder_id(), actualPo.getOrder_id(),
						"验证Order_id");
			}
		} else {
			while (iter.hasNext()) {

				Entry<String, HunterCatalogSettlementDetailBean> entry = iter
						.next();
				HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean = entry
						.getValue();
				String catalogId = entry.getKey();
				
				int productType = hunterCatalogSettlementDetailBean.getProductType();
				long childHunterId = hunterCatalogSettlementDetailBean
						.getChildHunterId();
				BigDecimal manageFee = hunterCatalogSettlementDetailBean
						.getManageFee();

				Logger.comment(String.format(
						"开始验证settlementId：%s，catalogId：%s", settlementId,
						catalogId));

				HunterSettlementManageFeeDetail actualPo = hunterSettlementManageFeeDetailWrapper
						.selectByChildHunterIdAndCatalogId(childHunterId,
								catalogId, settlementId);
				HunterSettlementManageFeeDetail expectPo = new HunterSettlementManageFeeDetail();

				BigDecimal currentLevelFeeRate = hunterCatalogSettlementDetailBean
						.getCurrentLevelFeeRate();
				String feeRateSource = null;
				
				if (hunterCatalogSettlementDetailBean.getNewRule()) {
					
					feeRateSource = currentLevelFeeRate.multiply(
							new BigDecimal("100")).setScale(2,
							BigDecimal.ROUND_DOWN)
							+ "%";
					
					expectPo.setFee_rate(currentLevelFeeRate.setScale(20));
					expectPo.setCurrent_level_fee_rate(currentLevelFeeRate
						.multiply(new BigDecimal("100")));
					expectPo.setBase_per_manage_amount(hunterCatalogSettlementDetailBean
							.getSinglePerBaseLineFee());
				} else {
					
					feeRateSource = productType == 2 ? currentLevelFeeRate.multiply(
							new BigDecimal("100")).setScale(2,
							BigDecimal.ROUND_DOWN)
							+ "%" : null;
					
					expectPo.setFee_rate(productType == 2 ? currentLevelFeeRate.setScale(20) : null);
					expectPo.setCurrent_level_fee_rate(productType == 2 ? currentLevelFeeRate
							.multiply(new BigDecimal("100")) : null);
					expectPo.setBase_per_manage_amount(productType == 2 ? hunterCatalogSettlementDetailBean
							.getSinglePerBaseLineFee() : null);
				}

				expectPo.setSettlement_id(settlementId);
				expectPo.setTotal_amount(manageFee.multiply(taxFeeRate)
						.setScale(2, RoundingMode.DOWN));
				expectPo.setSales_commission_amount(hunterCatalogSettlementDetailBean
						.getSalesCommission());
				expectPo.setChild_hunter_level(hunterCatalogSettlementDetailBean
						.getChildHunterLevel());
				expectPo.setChild_hunter_id(childHunterId);
				expectPo.setFee_rate_source(feeRateSource);
				expectPo.setFee_type(hunterCatalogSettlementDetailBean
						.getFeeType());
				expectPo.setProduct_type(hunterCatalogSettlementDetailBean
						.getProductType());
				expectPo.setCatalog_id(catalogId);
				expectPo.setFee_tax(BigDecimal.ONE.subtract(taxFeeRate));
				expectPo.setPer_manage_amount(hunterCatalogSettlementDetailBean.getSinglePerManageFee());
				expectPo.setOrder_id(hunterCatalogSettlementDetailBean.getOrderId());

				DataUtil.verify(expectPo.getSettlement_id(),
						actualPo.getSettlement_id(), "验证Settlement_id");
				DataUtil.verifyDecimalEquals(expectPo.getFee_rate(),
						actualPo.getFee_rate(), "验证Fee_rate");
				DataUtil.verify(expectPo.getTotal_amount(),
						actualPo.getTotal_amount(), "验证Total_amount");
				DataUtil.verify(expectPo.getSales_commission_amount(),
						actualPo.getSales_commission_amount(),
						"验证Sales_commission_amount");
				DataUtil.verify(expectPo.getChild_hunter_level(),
						actualPo.getChild_hunter_level(),
						"验证Child_hunter_level");
				DataUtil.verify(expectPo.getChild_hunter_id(),
						actualPo.getChild_hunter_id(), "验证Child_hunter_id");
				DataUtil.verify(expectPo.getCurrent_level_fee_rate(),
						actualPo.getCurrent_level_fee_rate(),
						"验证Current_level_fee_rate");
				DataUtil.verify(expectPo.getFee_rate_source(),
						actualPo.getFee_rate_source(), "验证Fee_rate_source");
				DataUtil.verify(expectPo.getFee_type(), actualPo.getFee_type(),
						"验证Fee_type");
				DataUtil.verify(expectPo.getProduct_type(),
						actualPo.getProduct_type(), "验证Product_type");
				DataUtil.verify(expectPo.getFee_tax(), actualPo.getFee_tax(),
						"验证Fee_tax");
				DataUtil.verify(expectPo.getFee_type(), actualPo.getFee_type(),
						"验证Fee_type");
				DataUtil.verify(expectPo.getBase_per_manage_amount(),
						actualPo.getBase_per_manage_amount(), "验证base_per_manage_amount");
				DataUtil.verify(expectPo.getPer_manage_amount(), actualPo.getPer_manage_amount(),
						"验证per_manage_amount");
				DataUtil.verify(expectPo.getOrder_id(), actualPo.getOrder_id(),
						"验证Order_id");
			}
		}
	}

	/**
	 * 校验HunterSettlementSalesDetail
	 * 
	 * @param orderId
	 * @param hunterOrderType
	 *            订单类型（1：大礼包订单，2：普通订单）
	 * @param catalogSettmentDetailMap
	 *            规格的计算明细map
	 * @throws InterruptedException
	 */
	private void verifyHunterSettlementSalesDetail(
			String settlementId,
			Map<String, HunterCatalogSettlementDetailBean> catalogSettmentDetailMap)
			throws InterruptedException {

		Logger.comment("开始验证HunterSettlementSalesDetail表");

		HunterSettlementSalesDetailWrapper hunterSettlementSalesDetailWrapper = new HunterSettlementSalesDetailWrapper();
		Iterator<Entry<String, HunterCatalogSettlementDetailBean>> iter = catalogSettmentDetailMap
				.entrySet().iterator();

		while (iter.hasNext()) {

			Entry<String, HunterCatalogSettlementDetailBean> entry = iter
					.next();
			HunterCatalogSettlementDetailBean hunterCatalogSettlementDetailBean = entry
					.getValue();
			String catalogId = entry.getKey();

			Logger.comment(String.format("开始验证settlementId：%s，catalogId：%s",
					settlementId, catalogId));

			OrderDetailPo orderDetailPo = hunterCatalogSettlementDetailBean
					.getOrderDetailPo();
			HunterSettlementSalesDetail salesDetail = hunterSettlementSalesDetailWrapper
					.selectBySettlementIdAndCatalogId(settlementId, catalogId);
			HunterSettlementSalesDetail expectDetail = new HunterSettlementSalesDetail();

			expectDetail.setSettlement_id(settlementId);
			expectDetail.setProduct_id(orderDetailPo.getProductId());
			expectDetail.setCatalog_id(catalogId);
			expectDetail.setTotal_amount(hunterCatalogSettlementDetailBean
					.getSalesCommission());
			expectDetail.setTotal_product_num(orderDetailPo.getProductCount());
			expectDetail
					.setCommission_per_prod(hunterCatalogSettlementDetailBean
							.getCatalogCommission());
			expectDetail.setProduct_price(orderDetailPo.getProductPrice());
			expectDetail
					.setRefund_product_num(hunterCatalogSettlementDetailBean
							.getRefundCount());
			expectDetail.setRefund_no(hunterCatalogSettlementDetailBean
					.getRefundNo());
			expectDetail.setPayable_amount(hunterCatalogSettlementDetailBean
					.getPayableAmount());
			expectDetail.setOrder_id(hunterCatalogSettlementDetailBean.getOrderId());
			expectDetail.setDivided_amount(hunterCatalogSettlementDetailBean.getDivided_amount());
			expectDetail.setCommission_proportion(hunterCatalogSettlementDetailBean.getSaleTerminalPercent());

			DataUtil.verify(expectDetail.getSettlement_id(),
					salesDetail.getSettlement_id(), "验证Settlement_id");
			DataUtil.verify(expectDetail.getProduct_id(),
					salesDetail.getProduct_id(), "验证Product_id");
			DataUtil.verify(expectDetail.getCatalog_id(),
					salesDetail.getCatalog_id(), "验证Catalog_id");
			DataUtil.verify(expectDetail.getTotal_amount(),
					salesDetail.getTotal_amount(), "验证Total_amount");
			DataUtil.verify(expectDetail.getTotal_product_num(),
					salesDetail.getTotal_product_num(), "验证Total_product_num");
			DataUtil.verify(expectDetail.getCommission_per_prod(),
					salesDetail.getCommission_per_prod(),
					"验证Commission_per_prod");
			DataUtil.verify(expectDetail.getProduct_price(),
					salesDetail.getProduct_price(), "验证Product_price");
			DataUtil.verify(hunterCatalogSettlementDetailBean.getProductType() == 1 ? 0 : expectDetail.getRefund_product_num(),
					salesDetail.getRefund_product_num(), "验证Refund_product_num");
			DataUtil.verify(hunterCatalogSettlementDetailBean.getProductType() == 1 ? null : expectDetail.getRefund_no(),
					salesDetail.getRefund_no(), "验证Refund_no");
			DataUtil.verifyDecimalEquals(expectDetail.getPayable_amount(),
					salesDetail.getPayable_amount(), "验证Payable_amount");
			DataUtil.verify(expectDetail.getOrder_id(),
					salesDetail.getOrder_id(), "验证Order_id");
			DataUtil.verifyDecimalEquals(expectDetail.getCommission_proportion(),
					salesDetail.getCommission_proportion(), "验证Commission_proportion");
			DataUtil.verifyDecimalEquals(expectDetail.getDivided_amount(),
					salesDetail.getDivided_amount(), "验证Divided_amount");
		}
	}

	// /**
	// * 校验HunterSaleAmountDetail
	// *
	// * @param orderId
	// */
	// private void verifyHunterSaleAmountDetail(Map<String, Object> expectMap)
	// {
	//
	// Logger.comment("开始验证HunterSaleAmountDetail表");
	//
	// HunterSaleAmountDetailWrapper hunterSaleAmountDetailWrapper = new
	// HunterSaleAmountDetailWrapper();
	// HunterSaleAmountDetail actualPo = hunterSaleAmountDetailWrapper
	// .selectByOrderIdAndHunterId((long) expectMap.get("orderId"),
	// (long) expectMap.get("hunterId"));
	// HunterSaleAmountDetail expectPo = new HunterSaleAmountDetail();
	// HunterRelationWrapper hunterRelationWrapper = new
	// HunterRelationWrapper();
	// HunterRelation hunterRelation = hunterRelationWrapper
	// .selectByPrimaryKey(actualPo.getHunter_id());
	// HunterSettlementWrapper hunterSettlementWrapper = new
	// HunterSettlementWrapper();
	// HunterSettlement hunterSettlement = hunterSettlementWrapper
	// .selectHunterSettlementByOrderIdAndHunterId(
	// (long) expectMap.get("hunterId"),
	// (long) expectMap.get("orderId"));
	//
	// expectPo.setOrder_id((long) expectMap.get("orderId"));
	// expectPo.setHunter_id((long) expectMap.get("hunterId"));
	//
	// if (null == hunterRelation || hunterRelation.getStatus() == 1) {
	//
	// expectPo.setSale_amount(BigDecimal.ZERO);
	// expectPo.setSum_status(0);
	// } else if (hunterSettlement.getSettlement_status() == 2) {
	//
	// expectPo.setSale_amount((BigDecimal) expectMap.get("sale_amount"));
	// expectPo.setSum_status(0);
	// } else {
	//
	// expectPo.setSale_amount((BigDecimal) expectMap.get("sale_amount"));
	// expectPo.setSum_status((int) expectMap.get("sum_status"));
	// }
	//
	// DataUtil.verify(expectPo.getOrder_id(), actualPo.getOrder_id(),
	// "验证Order_id");
	// DataUtil.verify(expectPo.getHunter_id(), actualPo.getHunter_id(),
	// "验证Hunter_id");
	// DataUtil.verify(expectPo.getSale_amount(), actualPo.getSale_amount(),
	// "验证Sale_amount");
	// DataUtil.verify(expectPo.getSum_status(), actualPo.getSum_status(),
	// "验证Sum_status");
	// }
	//
	// /**
	// * 校验SumHunterSaleAmount
	// *
	// * @param hunterId
	// * @param saleAmount
	// */
	// private void verifyHunterSaleAmount(
	// Map<Long, BigDecimal> beforeHunterSaleAmount, BigDecimal saleAmount) {
	//
	// Logger.comment("开始验证SumHunterSaleAmount表");
	//
	// SumHunterSaleAmountWrapper sumHunterSaleAmountWrapper = new
	// SumHunterSaleAmountWrapper();
	// HunterRelationWrapper hunterRelationWrapper = new
	// HunterRelationWrapper();
	// long hunterId = 0;
	// BigDecimal totalAmount = BigDecimal.ZERO;
	//
	// Iterator<Entry<Long, BigDecimal>> iter = beforeHunterSaleAmount
	// .entrySet().iterator();
	//
	// while (iter.hasNext()) {
	//
	// Entry<Long, BigDecimal> entry = iter.next();
	// hunterId = entry.getKey();
	// totalAmount = entry.getValue();
	// HunterRelation hunterRelation = hunterRelationWrapper
	// .selectByPrimaryKey(hunterId);
	//
	// if (totalAmount == null || hunterRelation.getStatus() == 1)
	// totalAmount = BigDecimal.ZERO;
	//
	// SumHunterSaleAmount actualPo = sumHunterSaleAmountWrapper
	// .selectByHunterId(hunterId);
	//
	// DataUtil.verify(hunterId, actualPo.getHunter_id(), "验证Hunter_id");
	// DataUtil.verify(totalAmount.add(saleAmount),
	// actualPo.getSale_amount(), "验证Sale_amount");
	// }
	// }

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_001() {
		Logger.start(true, "正常购买一份大礼包,未结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			// long hunterId = 1022;
			long hunterId = 20226434;

			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_002() {
		Logger.start(true, "正常购买一份普通商品,未结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// long hunterId = 20324277;
			long hunterId = 20226434;

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 100, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_003() {
		Logger.start(true, "优选团商品，hunter级别为1，未结算，验证数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1001;

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 3, 0);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			TradingCallService.confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_004() {
		Logger.start(true, "正常购买一份大礼包,结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1022;
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);

			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(12000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_005() {
		Logger.start(true, "正常购买一份普通商品,结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 24713026;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_006() {
		Logger.start(true, "优选团商品，hunter级别为2，验证数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 2001;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 3, 0);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			TradingCallService.confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_007() {
		Logger.start(true, "优选团商品，hunter级别为3，验证数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long hunterId = 3001;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 3, 0);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);
			
			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			TradingCallService.confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_008() {
		Logger.start(true, "正常购买一份普通商品,确认收货前，商品依次全部退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long hunterId = 25139693;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);

			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			HunterCallService.hunterOrderRefund(order, true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_009() {
		Logger.start(true, "正常购买一份普通商品,确认收货前，商品部分退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 25139693;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			HunterCallService.hunterOrderRefund(order, true, 5);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_010() {
		Logger.start(true, "正常购买一份优选团商品, hunter级别为1, 确认收货前，商品依次全部退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1001;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 3, 0);

			Order order = placeOrder.getOrderList().get(0);
			Long userId = placeOrder.getUserId();
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			HunterCallService.hunterOrderRefund(order, true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_011() {
		Logger.start(true, "正常购买一份优选团商品, hunter级别为2, 确认收货前，商品依次部分退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 2001;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 9, 0);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			HunterCallService.hunterOrderRefund(order, true, 5);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_012() {
		Logger.start(true, "正常购买一份普通商品,确认收货后，商品依次全部退款并结算");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 24713026;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			long sellerId = order.getSellerId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);
			
			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(5000);

			HunterCallService.hunterOrderRefund(order, true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_013() {
		Logger.start(true, "正常购买一份普通商品,确认收货后，商品部分退款并结算");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 24713026;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long sellerId = order.getSellerId();
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);
			
//			TradingCallService.cancelOrder(orderId, CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER, userId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(5000);

			HunterCallService.hunterOrderRefund(order, true, 2);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_014() {
		Logger.start(true, "正常购买一份优选团商品, hunter级别为3,确认收货后，商品依次全部退款并结算");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 3001;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 10, 0);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			long sellerId = order.getSellerId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);
			
			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(5000);

			HunterCallService.hunterOrderRefund(order, true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_015() {
		Logger.start(true, "正常购买一份优选团商品, hunter级别为4,确认收货后，商品部分退款并结算");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1001;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 10, 0);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long sellerId = order.getSellerId();
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(5000);

			HunterCallService.hunterOrderRefund(order, true, 1);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_016() {
		Logger.start(true, "正常购买一份普通商品,确认收货后，申请退货退款，无法结算");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1022;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long sellerId = order.getSellerId();
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(10000);

			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 只申请退款，但不同意退款
			HunterCallService.hunterOrderRefund(order, false, 5);

			Thread.sleep(4000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_017() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（五层级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_018() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（五层级别），只有一名合伙人");
		/**
		 *
		 * 1、A1为合伙人 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					1, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(0));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_019() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（五层级别），金牌服务商的上级为合伙人的第一位");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A1<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(0));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_020() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（五层级别），金牌服务商只有一名");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1，上线关系为A3<-B1
		 * 3、C1、C2、C3、C4为服务商，上线关系为B1<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 1,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(0));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_021() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（五层级别），服务商只有一名");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1为服务商，上线关系为B3<-C1 4、D1、D2、D3为推手，上线关系为C1<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					1, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_022() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（四层级别），没有合伙人级别");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_023() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（四层级别），没有金牌服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3
		 * 2、C1、C2、C3、C4为服务商，上线关系为A3<-C1<-C2<-C3<-C4
		 * 3、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 4、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, partnerList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_024() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（四层级别），没有服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、D1、D2、D3为推手，上线关系为B3<-D1<-D2<-D3 4、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_025() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（四层级别），没有推手级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4 4、p为C4的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("deprecation")
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_026() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（四层级别， 佣金金额为0），没有合伙人级别，佣金直接结算");
		/**
		 *
		 * 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false, true);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("deprecation")
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_027() {
		Logger.start(true, "特殊大礼包订单佣金和管理服务费计费规则（四层级别，服务商只有一个，没有合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q为服务商，上线关系为D<-Q
		 * 3、K、L、M为推手，上线关系为Q<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					1, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;

			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeSpecialGiftBagHunterOrder(hunterId, 10, userId, false, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_028() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（四层级别，金牌服务商只有一个，没有合伙人级别）");
		/**
		 *
		 1、D为金牌服务商，上线关系为D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 1, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(0));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_029() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（三层级别），没有金牌和服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、D1、D2、D3为推手，上线关系为A3<-D1<-D2<-D3
		 * 3、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					partnerList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_030() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（三层级别，没有服务商和推手级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、p为B3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));

			long hunterId = goldList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_031() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（三层级别，没有金牌和推手级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3
		 * 2、C1、C2、C3、C4为服务商，上线关系为A3<-C1<-C2<-C3<-C4 3、p为C3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, partnerList.get(2));

			long hunterId = serviceList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_032() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（三层级别，没有合伙人和服务商级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、K、L、M为推手，上线关系为D<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_033() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（三层级别，推手上线为B,没有合伙人和服务商级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、K、L、M为推手，上线关系为B<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_034() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（三层级别，没有合伙人和推手级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J 3、p为J的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_035() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（三层级别，没有合伙人和金牌服务商级别）");
		/**
		 *
		 1、Q、H、I、J为服务商，上线关系为Q<-H<-I<-J 2、K、L、M为推手，上线关系为J<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_036() {
		Logger.start(true,
				"大礼包订单佣金和管理服务费计费规则（三层级别，推手的上级为服务商的第一个，没有合伙人和金牌服务商级别）");
		/**
		 *
		 1、Q、H、I、J为服务商，上线关系为Q<-H<-I 2、K、L、M为推手，上线关系为Q<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_037() {
		Logger.start(true, "大礼包订单管理服务费和佣金计费规则（二层级别，仅有合伙人）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、p为A3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);

			long hunterId = partnerList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_038() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（二层级别，仅有金牌服务商");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、p为D的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);

			long hunterId = goldList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_039() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（二层级别，仅有服务商级别");
		/**
		 * 
		 1、Q、H、I、J为服务商，上线关系为Q<-H<-I<-J 2、p为J的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);

			long hunterId = serviceList.get(3);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_040() {
		Logger.start(true, "大礼包订单佣金和管理服务费计费规则（二层级别，仅有推手级别");
		/**
		 * 
		 1、K、L、M为推手，上线关系为Q<-K<-L<-M 2、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					0);

			long hunterId = hunterList.get(2);
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_041() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（五层级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();
			
			//long userId = 25136019;

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), (int)userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_042() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（五层级别），只有一名合伙人");
		/**
		 *
		 * 1、A1为合伙人 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					1, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(0));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_043() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（五层级别），金牌服务商的上级为合伙人的第一位");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A1<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(0));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_044() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（五层级别），金牌服务商只有一名");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1，上线关系为A3<-B1
		 * 3、C1、C2、C3、C4为服务商，上线关系为B1<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 1,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(0));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_045() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（五层级别），服务商只有一名");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1为服务商，上线关系为B3<-C1 4、D1、D2、D3为推手，上线关系为C1<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					1, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_046() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（四层级别），没有合伙人级别");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_047() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（四层级别），没有金牌服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3
		 * 2、C1、C2、C3、C4为服务商，上线关系为A3<-C1<-C2<-C3<-C4
		 * 3、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 4、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, partnerList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_048() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（四层级别），没有服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、D1、D2、D3为推手，上线关系为B3<-D1<-D2<-D3 4、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_049() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（四层级别），没有推手级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4 4、p为C4的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_050() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（四层级别，服务商只有一个，没有合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q为服务商，上线关系为D<-Q
		 * 3、K、L、M为推手，上线关系为Q<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					1, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_051() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（四层级别，金牌服务商只有一个，没有服务商级别）");
		/**
		 *
		 1、D为金牌服务商，上线关系为D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 1, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(0));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_052() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（四层级别），推手D3自购");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();
			
			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(2));
			
			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			
			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);
			
			Thread.sleep(3000);
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(userId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_053() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（四层级别），服务商直推");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、P为C4的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();
			
			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_054() {
		Logger.start(true, "普通订单管理服务费和佣金计费规则（三层级别），没有金牌和服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、D1、D2、D3为推手，上线关系为A3<-D1<-D2<-D3
		 * 3、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					partnerList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_055() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（三层级别，没有服务商和推手级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、p为B3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));

			long hunterId = goldList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_056() {
		Logger.start(true, "普通商品订单管理服务费和佣金计费规则（三层级别，没有金牌和推手级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3
		 * 2、C1、C2、C3、C4为服务商，上线关系为A3<-C1<-C2<-C3<-C4 3、p为C3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();
			
			//int userId = 25136019;
			
			
			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, partnerList.get(2));

			long hunterId = serviceList.get(2);
			//long hunterId = 25135582;
			
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_057() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（三层级别，没有合伙人和服务商级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、K、L、M为推手，上线关系为D<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_058() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（三层级别，推手的上级为金牌服务商的第一个，没有服务商级别和合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、K、L、M为推手，上线关系为B<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_059() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（三层级别，没有推手和合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J 3、p为J的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_060() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（三层级别，没有金牌服务商和合伙人级别）");
		/**
		 *
		 1、Q、H、I、J为服务商，上线关系为Q<-H<-I<-J 2、K、L、M为推手，上线关系为J<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_061() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（三层级别，推手的上级为服务商的第一个， 没有金牌服务商和合伙人级别）");
		/**
		 *
		 1、Q、H、I服务商，上线关系为Q<-H<-I 2、K、L、M为推手，上线关系为Q<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_062() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（三层级别， 没有合伙人级别，M自购商品）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(userId, userId, hunterOrderType);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_063() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（三层级别， 没有推手级别，C4自购商品）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();
			
			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(2);

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);
			
			Thread.sleep(5000);
			
			// 更新hunter等级
			hunterRelationWrapper.updateLevelByHunterId(userId, 2);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(userId, userId, hunterOrderType);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_064() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（二层级别，没有服务商、推手、合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、p为D的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);

			long hunterId = goldList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_065() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（二层级别，没有金牌服务商、推手、合伙人级别）");
		/**
		 *
		 1、Q、H、I、J为服务商，上线关系为Q<-H<-I<-J 2、p为J的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_066() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（二层级别， J自购商品，没有金牌服务商、推手级别）");
		/**
		 *
		 1、B、C、D为合伙人，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();
			
			// 构建hunterRelation
			List<Long> partnerList = HunterCallService
					.buildHunterRelation(4, 3, 0);
			List<Long> serivceList = HunterCallService.buildHunterRelation(2,
					4, partnerList.get(2));

			long hunterId = serivceList.get(3); 

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);

			// 更新hunter等级
			hunterRelationWrapper.updateLevelByHunterId(userId, 2);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(userId, userId, hunterOrderType);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_067() {
		Logger.start(true, "商品订单管理服务费计费规则（二层级别，没有金牌服务商、服务商、合伙人级别）");
		/**
		 *
		 1、K、L、M为推手，上线关系为K<-L<-M 2、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					0);

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_068() {
		Logger.start(true, "服务商管理服务费和佣金计费规则（二层级别，仅有合伙人）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、p为A3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);

			long hunterId = partnerList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, 10, userId, hunterOrderType,
							false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_069() {
		Logger.start(true, "普通商品订单佣金和管理服务费计费规则（一层级别， 合伙人D自购商品）");
		/**
		 *
		 1、B、C、D为合伙人，上线关系为B<-C<-D
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();
			
			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);

			long hunterId = partnerList.get(2);

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);

			// 更新hunter等级
			hunterRelationWrapper.updateLevelByHunterId(userId, 4);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(userId, userId, hunterOrderType);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	// @Test
	// @Category(P2.class)
	// @TestCase
	// public void Tc_HunterOrderSettlement_070() {
	// Logger.start(true, "订单价格小于最低分润价格，则订单不参加分润");
	//
	// try {
	// // 创建订单
	// Logger.comment("前置数据准备");
	//
	// OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	// List<OrderPo> orderList = orderShardingWapper
	// .selectHunterGiftBagOrderbyUserId(userId);
	//
	// if (orderList.size() > 0) {
	// for (OrderPo po : orderList) {
	// TradingCallService.cancelOrder(po.getOrderId(),
	// CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
	// }
	// }
	//
	// long hunterId = 1022;
	// int hunterOrderType = 1;
	// TradingServiceResp placeOrder = TradingCallService
	// .placeHunterOrder(hunterId, 1, userId, hunterOrderType,
	// false);
	// Long userId = placeOrder.getUserId();
	// long sellerId = placeOrder.getOrderList().get(0).getSellerId();
	// long orderId = placeOrder.getOrderList().get(0).getOrderId();
	// long tradingId = placeOrder.getTradingId();
	// BigDecimal totalPrice = placeOrder.getPayableAmount();
	//
	// Long thirdTradingId = TradingCallService.payOrder(userId,
	// BigDecimal.ZERO, tradingId, "13");
	//
	// PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
	// totalPrice.subtract(BigDecimal.ZERO).toString(),
	// userId.intValue());
	// TradingSyncService.getSyncResult(orderId);
	//
	// Thread.sleep(10000);
	//
	// //生成管理费结算明细
	// HunterCallService.onHunterRelationSearchedForManageFee(orderId,
	// hunterId);
	//
	// int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
	// .getOrderStatus();
	//
	// // 如果订单支付后没有自动接单，尝试手动接单
	// if (orderStatus == 2) {
	//
	// TradingCallService.sellerAcceptOrder(sellerId, orderId);
	// TradingSyncService.getSyncResult(orderId);
	// }
	//
	// // 拼邮国际段发货
	// TradingCallService.delivery(sellerId, orderId,
	// LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
	// TradingSyncService.getSyncResult(orderId);
	// // 拼邮国内段发货
	// TradingCallService.delivery(sellerId, orderId,
	// LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
	//
	// TradingCallService.confirmReceive(userId, orderId);
	//
	// Logger.comment("前置数据准备结束");
	//
	// TradingSyncService.getSyncResult(orderId);
	//
	// HunterSettlementWrapper hunterSettlementWrapper = new
	// HunterSettlementWrapper();
	// int size = hunterSettlementWrapper.selectByOrderId(orderId).size();
	//
	// DataUtil.verifyDateEquals(0, size, "订单价格小于266元不会生成分润");
	//
	// } catch (Exception e) {
	// Logger.fail(e);
	// }
	// }

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_071() {
		Logger.start(true, "已经禁用的用户，生成的结算单为废弃");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}
			
			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);

			long hunterId = partnerList.get(2);

			// 更改用户状态为废弃
			hunterRelationWrapper.updateStatusByHunterId(hunterId, 1);
			hunterRelationWrapper.updateStatusByHunterId(partnerList.get(1), 1);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_073() {
		Logger.start(true, "正常购买一份大礼包商品,确认收货前，商品依次全部退款，依旧计算佣金和管理费用");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1022;
			int hunterOrderType = 1;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			HunterCallService.hunterOrderRefund(order, true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	 }
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_074() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（五层级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_075() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（五层级别），只有一名合伙人");
		/**
		 *
		 * 1、A1为合伙人 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					1, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(0));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_076() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（五层级别），金牌服务商的上级为合伙人的第一位");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A1<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(0));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_077() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（五层级别），金牌服务商只有一名");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1，上线关系为A3<-B1
		 * 3、C1、C2、C3、C4为服务商，上线关系为B1<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 1,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(0));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_078() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（五层级别），服务商只有一名");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1为服务商，上线关系为B3<-C1 4、D1、D2、D3为推手，上线关系为C1<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					1, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_079() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（四层级别），没有合伙人级别");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_080() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（四层级别），没有金牌服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3
		 * 2、C1、C2、C3、C4为服务商，上线关系为A3<-C1<-C2<-C3<-C4
		 * 3、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 4、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, partnerList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_081() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（四层级别），没有服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、D1、D2、D3为推手，上线关系为B3<-D1<-D2<-D3 4、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_082() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（四层级别），没有推手级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4 4、p为C4的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_083() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（四层级别，服务商只有一个，没有合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q为服务商，上线关系为D<-Q
		 * 3、K、L、M为推手，上线关系为Q<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					1, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_084() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（四层级别，金牌服务商只有一个，没有服务商级别）");
		/**
		 *
		 1、D为金牌服务商，上线关系为D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M 4、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 1, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(0));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_085() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（四层级别），推手D3自购");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(2));
			
			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			
			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);
			
			Thread.sleep(3000);
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(userId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_086() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（四层级别），服务商直推");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、P为C4的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_087() {
		Logger.start(true, "优选订单管理服务费和佣金计费规则（三层级别），没有金牌和服务商级别");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、D1、D2、D3为推手，上线关系为A3<-D1<-D2<-D3
		 * 3、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					partnerList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_088() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（三层级别，没有服务商和推手级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、p为B3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));

			long hunterId = goldList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_089() {
		Logger.start(true, "优选商品订单管理服务费和佣金计费规则（三层级别，没有金牌和推手级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3
		 * 2、C1、C2、C3、C4为服务商，上线关系为A3<-C1<-C2<-C3<-C4 3、p为C3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, partnerList.get(2));

			long hunterId = serviceList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_090() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（三层级别，没有合伙人和服务商级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、K、L、M为推手，上线关系为D<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(2));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_091() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（三层级别，推手的上级为金牌服务商的第一个，没有服务商级别和合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、K、L、M为推手，上线关系为B<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					goldList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_092() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（三层级别，没有推手和合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J 3、p为J的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_093() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（三层级别，没有金牌服务商和合伙人级别）");
		/**
		 *
		 1、Q、H、I、J为服务商，上线关系为Q<-H<-I<-J 2、K、L、M为推手，上线关系为J<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_094() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（三层级别，推手的上级为服务商的第一个， 没有金牌服务商和合伙人级别）");
		/**
		 *
		 1、Q、H、I服务商，上线关系为Q<-H<-I 2、K、L、M为推手，上线关系为Q<-K<-L<-M 3、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(0));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_095() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（三层级别， 没有合伙人级别，M自购商品）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 * 3、K、L、M为推手，上线关系为J<-K<-L<-M
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(userId, 100, userId, false);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_096() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（三层级别， 没有推手级别，C4自购商品）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(2);

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);
			
			// 更新hunter等级
			hunterRelationWrapper.updateLevelByHunterId(userId, 2);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(userId, 100, userId, false);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_097() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（二层级别，没有服务商、推手、合伙人级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、p为D的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);

			long hunterId = goldList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 100, userId);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_098() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（二层级别，没有金牌服务商、推手、合伙人级别）");
		/**
		 *
		 1、Q、H、I、J为服务商，上线关系为Q<-H<-I<-J 2、p为J的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, 0);

			long hunterId = serviceList.get(3);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_099() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（二层级别， J自购商品，没有合伙人、推手级别）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D 2、Q、H、I、J为服务商，上线关系为D<-Q<-H<-I<-J
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();

			// 构建hunterRelation
			List<Long> goldList = HunterCallService
					.buildHunterRelation(3, 3, 0);
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));

			long hunterId = serviceList.get(3);

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);

			// 更新hunter等级
			hunterRelationWrapper.updateLevelByHunterId(userId, 2);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(userId, 100, userId, false);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_100() {
		Logger.start(true, "商品订单管理服务费计费规则（二层级别，没有金牌服务商、服务商、合伙人级别）");
		/**
		 *
		 1、K、L、M为推手，上线关系为K<-L<-M 2、p为M的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					0);

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_101() {
		Logger.start(true, "服务商管理服务费和佣金计费规则（二层级别，仅有合伙人）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、p为A3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);

			long hunterId = partnerList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(hunterId, 100, userId, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_102() {
		Logger.start(true, "优选商品订单佣金和管理服务费计费规则（一层级别， 合伙人D自购商品）");
		/**
		 *
		 1、B、C、D为金牌服务商，上线关系为B<-C<-D
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			long userId = new OrderCallService().createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					2, 0);

			long hunterId = partnerList.get(1);

			// 让用户成为hunter下线
			HunterCallService.buyHunterGiftBagOrder(userId, hunterId);

			// 更新hunter等级
			hunterRelationWrapper.updateLevelByHunterId(userId, 4);

			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					 .placeHunterOptimizedOrder(userId, 100, userId, false);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					userId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, userId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_103() {
		Logger.start(true, "优选商品和普通商品混合订单佣金和管理服务费计费规则（五层级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A1<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					1, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(0));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOptimizedOrder(hunterId, 100, userId, true);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, hunterOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@SuppressWarnings("deprecation")
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_HunterOrderSettlement_104() {
		Logger.start(true, "特殊大礼包订单管理服务费和佣金计费规则（五层级别）");
		/**
		 *
		 * 1、A1、A2、A3为合伙人，上线关系为A1<-A2<-A3 2、B1、B2、B3为金牌服务商，上线关系为A3<-B1<-B2<-B3
		 * 3、C1、C2、C3、C4为服务商，上线关系为B3<-C1<-C2<-C3<-C4
		 * 4、D1、D2、D3为推手，上线关系为C4<-D1<-D2<-D3 5、p为D3的下线
		 */

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建hunterRelation
			List<Long> partnerList = HunterCallService.buildHunterRelation(4,
					3, 0);
			List<Long> goldList = HunterCallService.buildHunterRelation(3, 3,
					partnerList.get(2));
			List<Long> serviceList = HunterCallService.buildHunterRelation(2,
					4, goldList.get(2));
			List<Long> hunterList = HunterCallService.buildHunterRelation(1, 3,
					serviceList.get(3));

			long hunterId = hunterList.get(2);
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeSpecialGiftBagHunterOrder(hunterId, 10, userId,
							false, false);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);
			
			Thread.sleep(10000);
			
			//生成管理费结算明细
			HunterCallService.onHunterRelationSearchedForManageFee(orderId,
					hunterId);

			int orderStatus = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getOrderStatus();

			// 如果订单支付后没有自动接单，尝试手动接单
			if (orderStatus == 2) {

				TradingCallService.sellerAcceptOrder(sellerId, orderId);
				TradingSyncService.getSyncResult(orderId);
			}

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, hunterId, 1, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	public static void main(String[] args) throws Exception {

		Ts_HunterOrderSettlement test = new Ts_HunterOrderSettlement();
		test.verifyDb(1520012440, 25182445, 1, true);

//		Map<Integer, HunterFeeTypeRelationBean> map = test
//				.calManageFeeOfHunter(25171976, 2, true);
//
//		for (Integer key : map.keySet()) {
//
//			HunterFeeTypeRelationBean bean = map.get(key);
//
//			System.out.println(String.format(
//					"Key: %s hunterId: %s hunterLevel: %s feeType: %s", key,
//					bean.getHunterId(), bean.getHunterLevel(),
//					bean.getFeeType()));
//		}

		// BigDecimal rate = new BigDecimal("4831").divide(new
		// BigDecimal("4851"), 32, RoundingMode.DOWN);
		//
		// System.out.println(new BigDecimal("49").multiply(rate).setScale(3,
		// RoundingMode.DOWN));
		// System.out.println(new BigDecimal("4831").divide(new
		// BigDecimal("99"), 2, RoundingMode.DOWN));
	}
}
